<template>
  <section>
    <el-tabs v-model="pageName">
      <el-tab-pane label="所有订单" name="allOrder">
        <el-form inline>
          <el-form-item label="">
            <el-row style="display: flex;flex-direction: row;width: 100%">
              <filter-tool class="filtertool" type="orderState" test="name" v-on:confirm="filterEvent($event,'state')"></filter-tool>
              <filter-tool class="filtertool" type="memberId" v-on:confirm="filterEvent"></filter-tool>
            </el-row>
          </el-form-item>
        </el-form>
        <all-order v-if="pageName === 'allOrder'" :orderList="orderList"></all-order>
      </el-tab-pane>
    </el-tabs>
    <el-pagination v-show="totalPage>0" style="margin-top:10px;" small layout="prev, pager, next" :page-count="totalPage" @current-change="goPage">
    </el-pagination>
  </section>
</template>

<script>
  import filterTool from '@/common/filterTool'
  import allOrder from './orderManagement/orderList'
  import errHandler from '@/assets/errHandler'
  import {mapGetters, mapActions, mapMutations} from 'vuex'
  export default {
    name: "index",
    components:{allOrder,filterTool},
    data(){
      return{
        pageName:'allOrder',
        totalPage:0,
        orderList:[],
        filterObj:{}
      }
    },
    watch:{
      pageName(nv,ov){
        if(nv){
          this.getOrderList()
        }
      }
    },
    computed:{
      ...mapGetters(['department'])
    },
    created(){
      //加载所有订单
      this.getOrderList()
    },
    methods: {
      ...mapActions({
        fetch: 'fetch'
      }),
      goPage(val){
        this.getOrderList(val-1,this.filterObj)
      },
      getOrderList(pageNo,filterObj){
        this.fetch({name:"getOrderList",data:{page:pageNo? pageNo:0,departmentId:this.department.id,...filterObj}})
          .then(res=>{
            console.log(res.content)
            this.orderList = res.content
            this.totalPage = res.totalPages
          })
          .catch(err=>{
            console.log(err)
            errHandler.handle(this,err)
          })
      },
      filterEvent(e,objK){
        console.log('筛选条事件---------',e,objK)
        for(let key in e){
          if(objK === undefined) this.filterObj[key]=e[key]
          else this.filterObj[objK]=e[key]
        }
        console.log('看下filterObj----------',this.filterObj)
        let tmp={}
        for(let k in this.filterObj){
          if(this.filterObj[k] !== undefined){
            tmp[k]=this.filterObj[k]
          }
        }
        console.log('看下tmp----------',tmp)
        this.getOrderList(0,tmp)//筛选入库单列表
      },
    }
  }
</script>

<style scoped>
  .filtertool{
    margin: 0 5px;
    width: 110px;
    border:0px solid red;
  }
</style>
